package com.shopping_back.serviceImpl;

import com.shopping_back.service.IPointService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class PointServiceImpl implements IPointService {

    @Override
    public int calculatePoints(Double amount,int memberLevel) {
        // 会员等级与积分倍率的映射
        Map<Integer, Double> memberRates = Map.of(
                1, 0.0,   // 银米会员
                2, 1.0,   // 金米会员
                3, 1.5,   // 白金会员
                4, 2.0,   // 钻石会员
                5, 3.0    // 至尊会员
        );

        // 获取对应会员等级的积分倍率
        Double rate = memberRates.get(memberLevel);
        if (rate == null) {
            throw new IllegalArgumentException("无效的会员等级");
        }

        // 计算积分
        return (int) (amount * rate);
    }
}